//promise
// localhost:8080/demo?a=index&c=index&page=1&date=2022-3-15
function demoPromise() {
    let promise = new Promise(function(resolve,reject) {
        setTimeout(function() {
            resolve("没有遵守承诺");
            console.log(promise);
        },2000);
    })
    return promise;
}

async function demoAwaitAndPromiseAndAsync() {
    let result = await demoPromise();
    console.log('1');
    console.log(result);
    console.log('2');
    console.log('3');
    console.log('4');
}
demoAwaitAndPromiseAndAsync();  
/**
 *  1
    没有遵守承诺
    2
    3
    4
 */
let mysql = require("mysql");
function query(sql, values) {
    return new Promise(function(resolve, reject) {
        let connection = mysql.createConnection({
            host:'localhost',
            user:'root',
            password:'123456',
            port:'3306',
            database:'situation'
        })
        connection.connect();
        connection.query(sql, values, function(err,result) {
            if(err) {
                reject(err);
            } else {
                resolve(result);
            }
            connection.end();
        });
    });
}
let sql = 'select * from china where id=?'

async function select(sql, values) {
    let result = await query(sql, values);
    console.log(result);
}
select(sql,2);